package com.hxx.demo.dao;

import com.hxx.demo.entity.Room;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Hxx
 */
@Mapper
public interface RoomDao {
    /**
     * @return void
     * @Author Hxx
     * @Description //TODO 添加宿舍信息
     * @Date 9:28 2019/11/7
     * @Param [room]
     **/
    @Insert("INSERT INTO room (id,buildId,roomId,num,createTime) VALUES (#{room.id},#{room.buildId},#{room.roomId},#{room.num},sysdate())")
    int addRoom(@Param("room") Room room);


    /**
     * @return int
     * @Author Hxx
     * @Description //TODO 编辑宿舍信息
     * @Date 14:29 2019/12/27
     * @Param []
     **/
    @Update("UPDATE room SET buildId=#{room.buildId},roomId=#{room.roomId},num=#{room.num},createTime=#{room.createTime} WHERE id =#{room.id}")
    int editRoom(@Param("room") Room room);

    /**
     * @return void
     * @Author Hxx
     * @Description //TODO 根据id删除宿舍信息
     * @Date 9:28 2019/11/7
     * @Param [roomId]
     **/
    @Delete("DELETE  FROM room where id=#{id}")
    int deltRoom(@Param("id") String id);


    /**
     * @return java.util.List<com.hxx.demo.entity.Room>
     * @Author Hxx
     * @Description //TODO 条件查找
     * @Date 13:49 2020/2/26
     * @Param [sql]
     **/
    @Select(" SELECT * FROM room WHERE  ${sql}")
    List<Room> findBykeywords(@Param("sql") String sql);


    /**
     * @return java.util.List<com.hxx.demo.entity.Room>
     * @Author Hxx
     * @Description //TODO 宿舍列表
     * @Date 13:42 2020/2/26
     * @Param []
     **/
    @Select(" SELECT * FROM room ORDER BY buildId ASC,roomId ASC ")
    List<Room> find();

    /**
     * @return int
     * @Author Hxx
     * @Description //TODO 批量删除
     * @Date 13:49 2020/2/26
     * @Param [ids]
     **/
    @Delete("<script>DELETE FROM room WHERE id IN <foreach collection=\"ids\" separator=\",\" open=\"(\" close=\")\" item=\"id\"> #{id} </foreach></script>")
    int deleteBatch(@Param("ids") String[] ids);

    @Select("SELECT * FROM room WHERE buildId=#{buildId} AND roomId=#{roomId} ")
    Room findByRoomId(@Param("buildId") Integer buildId, @Param("roomId") String roomId);

    /**
     * @return com.hxx.demo.entity.Room
     * @Author Hxx
     * @Description //TODO 根据id查询宿舍
     * @Date 14:04 2020/2/26
     * @Param [id]
     **/
    @Select("SELECT * FROM room WHERE id=#{id}")
    Room findById(@Param("id") String id);

    /**
     * @return java.util.List<com.hxx.demo.entity.Room>
     * @Author Hxx
     * @Description //TODO 下拉菜单
     * @Date 19:23 2020/2/27
     * @Param []
     **/
    @Select("SELECT DISTINCT buildId FROM room ORDER BY buildId ASC")
    List<Room> findMeanBuildId();

    /**
     * @return java.util.List<com.hxx.demo.entity.Room>
     * @Author Hxx
     * @Description //TODO 下拉菜单
     * @Date 19:23 2020/2/27
     * @Param []
     **/
    @Select("SELECT DISTINCT roomId FROM room ORDER BY roomId ASC")
    List<Room> findMeanRoomId();
}

